package com.example.application;

import com.example.exception.NotSignInException;
import com.example.net.Client;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import android.app.Application;

/**
 * 全局定义的变量
 * 
 * @author Administrator
 *
 */
public class QZApplication extends Application {

	// 全局的网络访问客户端
	private Client gClient = null;

	// 全局的用户信息
	private String userId = "";

	// 城市默认南京
	private String city = "南京";

	private static QZApplication instanceApplication;

	public QZApplication() {
		gClient = new Client();
	}

	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		instanceApplication = this;

		// 以下初始化universal-image框架
		// 创建默认的ImageLoader配置参数
		ImageLoaderConfiguration configuration = ImageLoaderConfiguration
				.createDefault(this);

		// Initialize ImageLoader with configuration.
		ImageLoader.getInstance().init(configuration);

	}

	// 获取全局唯一的客户端
	public Client getClient() {
		return gClient;
	}

	// 获取用户ID
	public String getUserId() throws NotSignInException {
		if (userId == "") {
			throw new NotSignInException();
		}
		return userId;
	}

	// 设置用户ID
	public void setUserId(String id) {
		if (id != null) {
			userId = id;
		}
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	/**
	 * 单例模式
	 * 
	 * @return
	 */
	public static QZApplication getInstance() {
		return instanceApplication;
	}

}
